from django.db import models

from user.models import UserModel


# Create your models here.

# 专业表
class MajorModel(models.Model):
    m_name = models.CharField(max_length=100, verbose_name='专业')

    class Meta:
        db_table = 'aymajor'

    def __str__(self):
        return self.m_name


# 部门表
class DeptModel(models.Model):
    de_name = models.CharField(max_length=100, verbose_name='科室名称')

    class Meta:
        db_table = 'aydept'

    def __str__(self):
        return self.de_name


# 职称表
class RankModel(models.Model):
    r_name = models.CharField(max_length=100, verbose_name='职称')

    class Meta:
        db_table = 'ayrank'

    def __str__(self):
        return self.r_name


# 医生表
class DoctorModel(models.Model):
    d_img = models.ImageField(upload_to="upload/", null=True, blank=True, verbose_name="人像")
    d_name = models.CharField(max_length=100, verbose_name='医生姓名')
    d_excel = models.CharField(max_length=200, verbose_name='擅长项目')
    d_desc = models.CharField(max_length=200, verbose_name='简介')
    is_long = models.BooleanField(default=False, verbose_name='是否远程会诊')
    is_online = models.BooleanField(default=False, verbose_name='是否在线')
    region = models.CharField(max_length=100, verbose_name='地区', default="暂无")
    major = models.ForeignKey(MajorModel, on_delete=models.CASCADE, verbose_name='专业')
    dept = models.ForeignKey(DeptModel, on_delete=models.CASCADE, verbose_name='科室')
    rank = models.ForeignKey(RankModel, on_delete=models.CASCADE, verbose_name='职称')
    is_show = models.BooleanField(default=False, verbose_name='是否显示')
    create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    update_time = models.DateTimeField(auto_now=True, verbose_name='更新时间', null=True, blank=True)
    is_del = models.BooleanField(default=False, verbose_name='是否删除')

    class Meta:
        db_table = 'aydoctor'

    def __str__(self):
        return self.d_name


# 会诊表
class ConsultationModel(models.Model):
    con_time = models.DateField(auto_now_add=True, verbose_name='会诊时间')
    doctor = models.ForeignKey(DoctorModel, on_delete=models.CASCADE, verbose_name='专家')
    user = models.ForeignKey(UserModel, on_delete=models.CASCADE, verbose_name='发起人')
    duration = models.IntegerField(default=3, verbose_name='时长')
    status = models.IntegerField(default=1, verbose_name='状态',
                                 choices=((1, '初步会诊'), (2, '辅助会诊'), (3, '详细问诊')))
    create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    update_time = models.DateTimeField(auto_now=True, verbose_name='更新时间', null=True, blank=True)
    is_del = models.BooleanField(default=False, verbose_name='是否删除')

    @property
    def con_date(self):
        return self.con_time.strftime("%Y-%m-%d")

    class Meta:
        db_table = 'ayconsultation'
